// gerenInfo/pages/passWord/passWord.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    passWord: '',
    old: '',
    new_Password: '',
    again_Password: '',
    error: false,
    color: 0, // 按钮颜色 0灰色 1蓝色
  },

  submit() {

    var old = this.data.old,
      passWord = this.data.passWord,
      error = this.data.error,
      new_Password = this.data.new_Password,
      again_Password = this.data.again_Password;

    if (old != passWord) {
      this.setData({
        error: true
      })
      return
    } else {
      error = false
    }
    if (new_Password.length == 0) {
      wx.showToast({
        title: '请填写新密码',
        icon: 'none'
      })
      return
    }
    if (new_Password.length < 6 || new_Password.length > 12) {
      wx.showToast({
        title: '密码长度6-12位数',
        icon: 'none'
      })
      return
    }
    if (again_Password.length == 0) {
      wx.showToast({
        title: '请填写确认密码',
        icon: 'none'
      })
      return
    }
    if (new_Password != again_Password) {
      wx.showToast({
        title: '两次密码不一致',
        icon: 'none'
      })
      return
    }
    if (old == again_Password) {
      wx.showToast({
        title: '新旧密码不能一致',
        icon: 'none'
      })
      return
    }


    var url = app.globalData.url + 'member/updateTel'

    app.wxRequest(url, {
      flag: 1,
      member_id: app.globalData.memberId,
      member_tel: again_Password
    }, res => {
      if (res.flag) {
        wx.showModal({
          title: '提示',
          content: '修改成功',
          showCancel: false,
          complete: (res) => {
            if (res.confirm) {
              var obj = JSON.parse(wx.getStorageSync('member'))
              obj.memberPassword = again_Password
              wx.setStorageSync('member', JSON.stringify(obj))
              wx.navigateBack()
            }
          }
        })
      }
    })

  },
  inputHandle() {
    var color = 0;
    if (this.data.old != '' && this.data.new_Password != '' && this.data.again_Password != '') {
      color = 1
    } else {
      color = 0
    }
    this.setData({
      color
    })

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var memberPassword = JSON.parse(wx.getStorageSync('member')).memberPassword
    this.setData({
      passWord: memberPassword
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})